package com.system.wechat.composite;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MenuComposite extends AbstractMenuItem {
    private Long parentId;
    private Long id;
    private String name;
    private String type;
    private String url;
    private String meunKey;
    private Date createTime;
    private Date updateTime;
    private List<AbstractMenuItem> child = new ArrayList<>();

    @Override
    public void addProductItem(AbstractMenuItem item) {
        this.child.add(item);
    }

    @Override
    public void delProductChild(AbstractMenuItem item) {
        MenuComposite removeItem = (MenuComposite) item;
        Iterator iterator = child.iterator();
        while (iterator.hasNext()) {
            MenuComposite composite = (MenuComposite) iterator.next();
            if(composite.getId() == removeItem.getId()) {
                iterator.remove();
                break;
            }
        }
    }
}
